package com.fernfx.xingtan.common.pullrefresh;

import com.fernfx.xingtan.utils.ToastUtil;
import com.lcodecore.tkrefreshlayout.RefreshListenerAdapter;
import com.lcodecore.tkrefreshlayout.TwinklingRefreshLayout;

import static com.fernfx.xingtan.common.pullrefresh.PullToRefreshActivity.HAVE_DOMAIN_STATUS;
import static com.fernfx.xingtan.common.pullrefresh.PullToRefreshActivity.MY_POCKET_MONEY_STATUS;
import static com.fernfx.xingtan.common.pullrefresh.PullToRefreshActivity.MY_PRINCIPAL_STATUS;
import static com.fernfx.xingtan.common.pullrefresh.PullToRefreshActivity.PURCHASE_HISTROY_STATUS;
import static com.fernfx.xingtan.common.pullrefresh.PullToRefreshActivity.RETRUN_DOMAIN_STATUS;

/**
 * Created by admin on 2018/8/20.
 */

public final class PullToRefreshArgs {
    public static class MyPmoneyButtonDisplay implements PullToRefreshAdapter.ButtonDisplay {

        @Override
        public int getStatus() {
            return MY_POCKET_MONEY_STATUS;
        }
    }

    /*
     * 金额记录
     */
    public static class MyPrincipalButtonDisplay implements PullToRefreshAdapter.ButtonDisplay {

        @Override
        public int getStatus() {
            return MY_PRINCIPAL_STATUS;
        }
    }

    /*
   * 购买记录
   */
    public static class PurchaseHistroyButtonDisplay implements PullToRefreshAdapter.ButtonDisplay {

        @Override
        public int getStatus() {
            return PURCHASE_HISTROY_STATUS;
        }
    }

    /*
    * 拥有的领土
    */
    public static class HaveDomainButtonDisplay implements PullToRefreshAdapter.ButtonDisplay {

        @Override
        public int getStatus() {
            return HAVE_DOMAIN_STATUS;
        }
    }

    /*
    * 退还的领土
    */
    public static class RetrunDomainButtonDisplay implements PullToRefreshAdapter.ButtonDisplay {

        @Override
        public int getStatus() {
            return RETRUN_DOMAIN_STATUS;
        }
    }



    public static class BaseRefreshListener extends RefreshListenerAdapter {

        private PullToRefreshActivity pullToRefreshActivity;

        public BaseRefreshListener(PullToRefreshActivity pullToRefreshActivity) {
            this.pullToRefreshActivity = pullToRefreshActivity;
        }

        @Override
        public void onRefresh(final TwinklingRefreshLayout refreshLayout) {
            pullToRefreshActivity.index = 1;
            pullToRefreshActivity.count = 10;
            pullToRefreshActivity.loadFlag = true;
            pullToRefreshActivity.isLoadMore = true;
            //请求接口
            pullToRefreshActivity.request();
        }

        @Override
        public void onLoadMore(final TwinklingRefreshLayout refreshLayout) {
            if (!pullToRefreshActivity.isLoadMore) {
                ToastUtil.showCentertoast("已是最后一页");
                pullToRefreshActivity.pullRefreshRlt.finishLoadmore();
                return;
            }
            pullToRefreshActivity.index +=1;
            pullToRefreshActivity.count = 10;
            pullToRefreshActivity.loadFlag = false;
            //请求接口
            pullToRefreshActivity.request();
        }
    }
}
